﻿<UserControl x:Class="MvvmNavigation.CustomerView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.Resources>
      <my:CustomerViewModel x:Key="vm" xmlns:my="clr-namespace:MvvmNavigation">
        <my:CustomerViewModel.Customer>
          <my:Customer CustomerId="123" CustomerName="John Doe" City="New York"/>
        </my:CustomerViewModel.Customer>
      </my:CustomerViewModel>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White" Height="150" Width="300" 
          DataContext="{Binding Source={StaticResource vm}}" VerticalAlignment="Top" HorizontalAlignment="Left">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <sdk:Label Content="Customer Id:" Grid.Row="0" />
        <TextBox Grid.Row="0" Grid.Column="1" Height="30"
                 Text="{Binding Path=Model.CustomerId}" />
        <sdk:Label Content="Customer Name:" Grid.Row="1" />
        <TextBox Grid.Row="1" Grid.Column="1" Height="30"
                 Text="{Binding Path=Model.CustomerName}" />
        <sdk:Label Content="Customer City:" Grid.Row="2" />
        <TextBox Grid.Row="2" Grid.Column="1" Height="30"
                 Text="{Binding Path=Model.City}" />
        <!-- Method in view-model will navigate home after 'saving' -->
      <Button Grid.Row="3" Grid.ColumnSpan="2" Content="Save"
              Height="30" Width="100">
        <!-- Add reference to Microsoft.Expression.Interactions.dll, System.Windows.Interactivity.dll -->
        <!-- Use mvvmxmlns snippet to add i and ei namespace prefixes -->
        <i:Interaction.Triggers>
          <i:EventTrigger EventName="Click">
            <ei:CallMethodAction
                    TargetObject="{Binding}"
                    MethodName="Save"/>
          </i:EventTrigger>
        </i:Interaction.Triggers>
      </Button>
    </Grid>
</UserControl>
